package a07_二叉树;

/**
 * <p>
 * a15_左叶子之和复习0
 * </p>
 *
 * @author flyduck
 * @since 2024/12/31
 */
public class a15_左叶子之和复习0 {

    public int sumOfLeftLeaves(TreeNode root) {
        traversal(root);
        return leftLeavesSums;
    }

    private int leftLeavesSums = 0;

    public void traversal(TreeNode currentNode){
        if (currentNode == null) {
            return;
        }
        if (currentNode.left != null && currentNode.left.left == null && currentNode.left.right == null) {
            leftLeavesSums = leftLeavesSums + currentNode.left.val;
        }
        traversal(currentNode.left);
        traversal(currentNode.right);
    }
}
